package com.example.easyexcel.controller;

import com.example.easyexcel.service.HutoolAssetTargetInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RequiredArgsConstructor
@RestController
@RequestMapping("/asset")
public class ExcelImportController {
    private final HutoolAssetTargetInfoService hutoolAssetTargetInfoService;

    @PostMapping("/import_Hutool_ExcelImport")
    public ResponseEntity<String> importExcel(@RequestParam("file") MultipartFile file) {
        try {
            hutoolAssetTargetInfoService.importTargetExcel(file);
            return ResponseEntity.ok("Excel导入成功");
        } catch (Exception e) {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
                    .body("Excel导入失败: " + e.getMessage());
        }
    }
}
